class Solution {
    int val(char x) {
        if ('A'<=x && x<='Z')
            return (int)x-(int)'A'+(int)'a';
        else if (('a'<=x && x<='z') || ('0'<=x && x<='9'))
            return (int)x;
        else
            return -1;
    }
public:
    bool isPalindrome(string s) {
        int h=0, t=s.size()-1;
        while (h<t) {
            while (h<=t && val(s[h])==-1) ++h;
            while (h<=t && val(s[t])==-1) --t;
            if (h<=t && val(s[h])!=val(s[t])) return false; else ++h,--t;
        }
        return true;
    }
};
